<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/14 0014
 * Time: 17:08
 */
namespace app\api\controller;
use app\admin\model\NoticeModel;
use app\api\model\Api as Apis;
use app\index\model\GetUser;
use think\Request;

class Del
{
    /**删除公告
     * @param Request $request
     * @return \think\response\Json
     */
    public function notice(Request $request){
        $data = $request->param();
        if(!$data['id']||!$data['token']){
            return returns(203,'参数有误');
        }
        if(!$user = GetUser::get($data['token'])){
            return returns();
        }
        $data = NoticeModel::getNotice()
            ->where('notice.id',$data['id'])
            ->find();
        $quan = '删除部门公告';
        if(!$data){
            $data = NoticeModel::getNotice(false)
                ->where('notice.id',$data['id'])
                ->find();
            $quan = '删除公司公告';
        }
        if(!Apis::AuthIndex($quan,$user)){
            return returns(205,'你的权限不足');
        }
        if(NoticeModel::delNotice('id',$data['id'])){
            return returns(200,'删除成功');
        }else{
            return returns(204,'删除失败');
        }
    }
}